import 'package:base_moudle/index.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hy_flutter_utils/widgets/hy_container.dart';

class HyWorkStoreDrawerPage extends StatelessWidget {
  static Future<String?>? push(
      {required List<String> arr,
      required BuildContext context,
      int seleted = 0}) {
    return showCupertinoDialog(
        context: context,
        builder: (BuildContext context) {
          return GestureDetector(
            child: Row(
              children: [
                Expanded(
                    child: Container(
                  color: ColorHex('#000000', opcity: 0.5),
                )),
                SizedBox(
                  width: Get.width * 0.81,
                  child: HyWorkStoreDrawerPage(
                    types: arr,
                    seleted: seleted,
                  ),
                )
              ],
            ),
            onHorizontalDragEnd: (_) {
              Get.back();
            },
            onTap: () {
              Get.back();
            },
          );
        });
    ;
  }

  HyWorkStoreDrawerPage({required this.types, this.seleted = 0});

  List<String> types;

  int seleted = 0;

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: SafeArea(
        child: Column(
          children: [
            ZsText(
              '应用分类',
              fontSize: 20,
              fontWeight: FontWeight.bold,
              left: 26,
              top: 20,
              bottom: 20,
            ).intoContainer(alignment: Alignment.centerLeft),
            Expanded(
                child: Container(
              padding: const EdgeInsets.fromLTRB(26, 20, 26, 20),
              child: GridView.builder(
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 2,
                    crossAxisSpacing: 16,
                    childAspectRatio: 2.5,
                    mainAxisSpacing: 16),
                physics: const NeverScrollableScrollPhysics(),
                //增加
                // shrinkWrap: true,
                //增加
                itemCount: types.length,
                itemBuilder: (BuildContext ctx, int index) {
                  String name = types[index];
                  bool isSelected = index == seleted;
                  Color color =
                      isSelected ? ColorHex('#207EFA') : ColorHex('#666666');
                  Color back = color.withOpacity(0.05);

                  return HYContainer(
                    backgroundColor: back,
                    borderRadius: BorderRadius.circular(4),
                    alignment: Alignment.center,
                    child: ZsText(
                      name,
                      color: color,
                      fontWeight: FontWeight.bold,
                    ),
                    onTap: () {
                      Get.back(result: name);
                    },
                  );
                },
              ),
            ))
          ],
        ),
      ),
    );
  }
}
